package com.hexiang.rocketmq.mq.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class SimpleBatchSpringMessageProducer {

    private static final String TOPIC = "test_simple_batch_spring_topic";

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public void sendBatchMsg() {
        List<Message> messages = new ArrayList<>();
        messages.add(new Message(TOPIC, "TagA", "OrderID001", "Hello world 0".getBytes()));
        messages.add(new Message(TOPIC, "TagA", "OrderID002", "Hello world 1".getBytes()));
        messages.add(new Message(TOPIC, "TagA", "OrderID003", "Hello world 2".getBytes()));

        SendResult sendResult = rocketMQTemplate.syncSend(TOPIC, messages);
        // 通过sendResult返回消息是否成功送达
        log.warn("sendResult={} ", sendResult);
    }

}